#include<cstdlib>
#include<map>
#include "Monde.h"
#include "Element.h"
#include "Position.h"
#include "Constantes.h"
#include<iostream>
#include <time.h>

using namespace std;

Element::Element(Monde * _m, int _id, int _vis, int _vit, int _vie) {
    constantes c;

    nbTours = 0;
    indexMonde = _id;
    vitesse = _vit;
    vision = _vis;

    if(_vie <= c.getPtsVieMax() && _vie >= c.getPtsVieMin())
        ptVie = _vie;
    else {
        if(_vie > c.getPtsVieMax())
            ptVie = c.getPtsVieMax();
        else
            ptVie = c.getPtsVieMin();
    }
    ptVieMax = ptVie;
    //Position p;
    mondeRef = _m;
}

/*Position Element::getPos() {
    return p;
}*/

int Element::getNbPts() {
    return ptVie;
}

int Element::getNbPtsMax() {
    return ptVieMax;
}

int Element::getVitesse() {
    return vitesse;
}

int Element::getVision() {
    return vision;
}

void Element::setIndice(int _i) {
    indexMonde = _i;
}

void Element::enleverPts(const int nb) {
    ptVie -= nb;
    if(ptVie < 0)
        ptVie = 0;
}

void Element::ajouterPts(const int nb) {
    ptVie += nb;
    if(ptVie > ptVieMax)
        ptVie = ptVieMax;
}

Position * Element::getPos() {
    Position * p = NULL;
    map<Position *,int> m = mondeRef->getMap();
    bool trouve = false;

    map<Position *,int>::iterator iter;
    iter = m.begin();
    while(iter != m.end() && !trouve) {
        if(iter->second == indexMonde) {
            p = iter->first;
            trouve = true;
        }
        iter++;
    }

    return p;
}

void Element::evoluer() {
}

int Element::getNbTours() {
    return nbTours;
}

void Element::changeID(int newID) {
    indexMonde = newID;
}

int Element::getIndexMonde() {
    return indexMonde;
}
